<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // code-2
    // 使用 switch 优化
    function getColor2(code){
      switch(code){
        case '200':
          return 'blue-blue'
          // break
        case '201':
          return 'green-green'
          // break
        case '202':
          return 'red-red'
          // break
        default:
          return 'other-other'
          // break
      }
    }
    console.log(getColor2('200'))


    // code-3
    // 使用映射优化 
    function getColor3(code){
      var colorMap = {
        '200': 'blue-blue',
        '201': 'green-green',
        '202': 'red-red',
      }
      return colorMap[code] || 'other-other'
    }
    console.log(getColor3('200'))

  </script>
</body>
</html>